# encoding: utf-8
require File.expand_path('../models/Friend', File.dirname(__FILE__))
require File.expand_path('../models/Vipinfo', File.dirname(__FILE__))
require File.expand_path('../models/VipDiscountCard', File.dirname(__FILE__))
require 'mysql2'
require 'json'
class SelectFriend < Controller
  def select
    client=Mysql2::Client.new(:host => "112.124.60.115", :username => "root",:password=>"guavaguava00",:database=>"e9")
    p=@params[:uid]
    callback=@params[:callback]
    u="select * from vipinfo c where uid in (select userid from friend where M_userid=#{p})"
    s="select * from VipDiscountCard  where uid in (select userid from friend where M_userid=#{p})"
   # r=client.query("select * from vipinfo c where uid in (select userid from friend where M_userid=#{p})");
   r=client.query("select * from  (#{s}) s right join (#{u}) u on s.uid=u.uid");
    client.close
   callback+"("+r.to_json+")"

  end
  def allgoods
    callback=@params[:callback]
    sorts=@params[:sorts]
    goodsequence=@params[:goodsequence]
    client=Mysql2::Client.new(:host => "112.124.60.115", :username => "root",:password=>"guavaguava00",:database=>"e9")
  #  u="select * from goods "
  #  i="select * from IsGoods";
  #  s="select * from Selling"
    #(Selling  left join  g on Selling.gid=goods.id)
     r=client.query("select * from  goods  left join IsGoods  on IsGoods.gid=goods.id left join selling on goods.id=selling.gid where goods.isvip='1' order by #{sorts} #{goodsequence}" );
   # r=client.query(s);
    client.close
    callback+"("+r.to_json+")"
  end
 def tidgoods
   callback=@params[:callback]
   sorts=@params[:sorts]
   goodsequence=@params[:goodsequence]
   t=@params[:tid]
   client=Mysql2::Client.new(:host => "112.124.60.115", :username => "root",:password=>"guavaguava00",:database=>"e9")
   #  u="select * from goods "
   #  i="select * from IsGoods";
   #  s="select * from Selling"
   #(Selling  left join  g on Selling.gid=goods.id)
   r=client.query("select * from  goods  left join IsGoods  on IsGoods.gid=goods.id left join selling on goods.id=selling.gid where goods.isvip='1'and tid=#{t} order by #{sorts} #{goodsequence}" );
   # r=client.query(s);
   client.close
   callback+"("+r.to_json+")"
 end
end